package com.lynu.controller;

import com.lynu.pojo.Headline;
import com.lynu.pojo.PortalOv;
import com.lynu.service.HeadlineService;
import com.lynu.utils.JwtHelper;
import com.lynu.utils.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
public class HeadLineController {
    @Autowired
    private HeadlineService headlineService;
    @Autowired
    private JwtHelper jwtHelper;
    @PostMapping("portal/findNewsPage")
    public Result findNewPages(@RequestBody PortalOv portalOv){
        return headlineService.findNewsPages(portalOv);
    }
    @PostMapping("portal/showHeadlineDetail")
    public Result showHeadLineDetail(@Param(value = "hid") Integer hid){
        return headlineService.showHeadLineDetail(hid);
    }
    @PostMapping("headline/publish")
    public Result publish(@RequestBody Headline headline, @RequestHeader(value = "token") String token){
        int uid=jwtHelper.getUserId(token).intValue();
        headline.setPublisher(uid);
        Result result=headlineService.publish(headline);
        return result;


    }
    @PostMapping("/headline/findHeadlineByHid")
    public Result findHeadlineByHid(@Param("hid") Integer hid){
        return headlineService.findHeadlineByHid(hid);
    }
    @PostMapping("/headline/update")
    public Result update(@RequestBody Headline headline){
        return headlineService.update(headline);
    }
    @PostMapping("headline/removeByHid")
    public Result removeByHid(@Param(value = "hid") Integer hid){
        return headlineService.removeByHid(hid);
    };

}
